Skip to content

doc(id): used-capability derivation tool spec (#5998) - #8499

Closed
dezren39 wants to merge 1 commit into
mainfrom
queue/14829-5998-capscan-spec
Closed

dezren39 wants to merge 1 commit into
mainfrom
queue/14829-5998-capscan-spec

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Closes #5998 — the used-capability derivation tool spec, per the issue's "done looks like" (a tool spec sufficient to implement without further design decisions) and the triage of record on #5998 (comment 6700990165).

Deliverable: doc/2026-11-11_design_id5998.md (the pkgs/id/doc/ design-doc location), spec only — no implementation.

What it pins:

  • Inputs & home: a Rust capscan binary in pkgs/id linking id-core (the catalog is PROVIDER_REGISTRY from the same tree, never a copied list); inputs are the entry Roc modules, the roc-world platform tree, and a world id — deliberately not the declared wants or any registry state, since used_static is a property of code + catalog only.
  • Algorithm: source closure over import edges (unresolvable import = hard failure, no partial certification) → def graph → reachability from the platform entry points (init/update/view/wants/…) → use extraction: platform-module imports, capability string literals (including the time.tick:5000 subscription form), and platform builder defs counted exactly when reachable.
  • Over-approximation rules (normative): dead defs excluded; a platform function passed as a value counts as used, with its full emitted set (the conservative rule from the triage, pending id: design: programming model — pure libraries with platform/context passed in by the core app #5963); a direct-forwarder rule so capability names passed through app helpers are counted at their literal call sites.
  • Dynamic-dispatch limitation, explicit: computed/concatenated/runtime-loaded capability names are never guessed — they produce an unresolved-capability diagnostic and certified: false, i.e. an explicitly marked lower bound for the id: design program: worlds — advanced Roc libraries, capabilities, permissions, dynamic user functions, licensing (2026-11-04 brief) #5955 dynamic-loading exception policy to grade.
  • Output schema: exactly the id: design: capability model — requested vs discovered-used sets, registry listing, custom-compiled platforms #5958 design record's registry representation (comment 6720327099 §5) — used.static as the sorted BTreeSet<String> of catalog names, keyed by a BLAKE3 build_hash over the scanned closure, with catalog_commit/vocab_version provenance — so requested vs used is a plain set difference and the S16 registry line needs no adapter.
  • Acceptance fixtures: six worked expectations against examples/roc-chat covering reachability, value-passing, computed names, subscription arguments, and non-catalog literals.

Premises were re-verified against current main before drafting (catalog macro/manifest shape, literal cap naming in RocCap.issue call sites, Wants/CapLedger set types, the #5958 record).


🤖 agent-note:v1 — queue task 14829 (lane code-g). Spec follow-on from task 14368's triage of #5998.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Design record for the static discovery producer of the capability
registry's used.set: a call-graph scan over a world program's Roc
source closure against the world_caps.rs provider catalog.

Pins everything an implementer needs: inputs (entry modules, the
roc-world platform tree, the linked id-core catalog), the closure /
def-graph / reachability algorithm with the platform entry points as
roots, the use-extraction rules (platform-module imports, capability
string literals including the subscription argument form, platform
builders counted when reachable), the normative over-approximation
rules (dead defs excluded; a platform function passed as a value
counts as used with its full emitted set, per the #5998 triage
pending #5963; the direct-forwarder rule for capability parameters),
and the dynamic-dispatch limitation stated explicitly (computed or
runtime-loaded capability names produce an unresolved-capability
diagnostic and certified: false — an explicitly marked lower bound,
never a silent one).

Output schema is exactly the #5958 design record's registry
representation: used.static as the sorted BTreeSet<String> of catalog
names keyed by a BLAKE3 build hash over the scanned closure, with
catalog_commit and vocab_version provenance, so requested vs used is
a plain set difference. Six worked acceptance fixtures against
examples/roc-chat close the record.

Spec only; no implementation. Worked by the repo-health queue
worker (lane code-g, task 14829).
@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 03:41
@coderabbitai

coderabbitai Bot commented Nov 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 65db9f3d-f37f-48a6-bf48-9f30984e74a3
Commits

Reviewing files that changed from the base of the PR and between 56cf191 and 23de016.

Files selected for processing: 1

  • doc/2026-11-11_design_id5998.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T03:47:03.361256Z 23de016 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23de016aed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

**Step 4 — Use extraction.** For each reachable def, collect:

- **(a) Module uses.** An `import` of a module whose name is a `PlatformModule` catalog entry (`Key`, `Screen`, `RocJson`, `RocGrid`, `RocCap`, `RocText`) adds that entry. The import counts when the importing module contains at least one reachable def. (Importing a platform module is how a program gains the module's values at all, so the module entry is used exactly when reachable code can name it.)
- **(b) Capability literals.** Every string literal in the def whose content — after stripping one optional `:<args>` suffix (the subscription argument form, e.g. `time.tick:5000`) — is a host-provider catalog name adds that name. This is the primary rule: capabilities are named as data (§Context), so the literal *is* the use site, whether it appears as a `RocCap.issue` argument, inside a `"cap"` field of a request document the def builds, or in a `subscribe` list. It applies equally to literals inside platform-module defs (the `RocCap.chat_request` builder's embedded `"chat.say"` counts when — and only when — that builder def is reachable).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Extract capabilities from serialized wants documents

The existing pkgs/id/examples/territory/main.roc:115 returns its entire wants document as one escaped JSON string containing a players subscription. That literal's content is not itself a catalog name, so this extraction rule omits players; because there is no computed capability expression, §5.4 also provides no reason to mark the result uncertified. An implementation following this specification would therefore certify an incomplete set for an existing world. Specify extraction from serialized wants documents, or require an uncertified result when their capability contents cannot be resolved.

Useful? React with 👍 / 👎.


**Step 1 — Source closure.** Starting from the entry modules, follow `import` edges (`import pf.<Module>`, `import <Module>`) across the app tree and the platform directory until fixpoint. Every import must resolve to a file in one of the two trees; an unresolvable import is an incomplete closure → exit `2` with the unresolved edge named. Files in the trees that are never imported are not scanned.

**Step 2 — Def graph.** For each file in the closure, enumerate its top-level definitions (Roc `name = value` / `name : type` + definition pairs, including defs inside nominal-type namespaces such as `RocCap.{ … }` blocks). A def's identity is `(module, name)`. Build edges def → def for every identifier reference in a def's body that resolves to a top-level def in the closure (qualified `Module.name` references resolve directly; unqualified references resolve within the module, then via its imports). String literals and comments are stripped before reference extraction (but see step 4: literal extraction happens first, per def). References that resolve to Roc builtin/stdlib names (not in the closure) are leaves.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve executable references inside string interpolations

For a reachable definition such as wants = |model| "${make_wants(model)}", stripping the string before reference extraction removes the call to make_wants. The helper is then classified as dead, and any capability literals in its request builders disappear from the supposedly certified upper bound. Roc interpolation executes ordinary expressions, as existing examples demonstrate in pkgs/id/examples/territory/main.roc:110. Strip literal text while recursively retaining references inside interpolation expressions.

Useful? React with 👍 / 👎.

- records a diagnostic `{ file, line, column, kind: "unresolved-capability" }` in the output (§6);
- sets `certified: false` on the output.

A scan with any such site is an **uncertified** result: its `used_static` is a lower bound for that build, not the upper bound #5958's presentation requires, and consumers (the registry, the #5955 dynamic-loading exception policy) must treat it as such. Unknown names that are literal but absent from the catalog are **not** diagnostics: they are dropped from the set (the catalog is the vocabulary; `is_known` already teaches the runtime the same convention) — exit code `3` is reserved for a future catalog-attestation mode and is not produced by this version. Runtime-loaded code is out of the closure by definition; worlds that load code dynamically are exactly the uncertified case, and marking them — not analysing them — is this tool's whole obligation under #5955's split.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid promising a lower bound for uncertified results

When a reachable definition contains both a capability literal in a never-taken branch and an unresolved computed request, §4 retains the former while §5.4 omits the latter. The resulting set can contain capabilities the build cannot exercise and omit capabilities it can exercise, so it is neither an upper nor a lower bound. Calling it a lower bound and requiring registry/policy consumers to treat it that way incorrectly promises that every retained member is a genuine possible use. Specify uncertified output as incomplete candidate evidence with possible false positives, rather than a guaranteed subset.

Useful? React with 👍 / 👎.

@dezren39

Copy link
Copy Markdown
Member Author

Closing as a duplicate of canonical PR #8448 for issue #5998 (same task 14829).

PR #8499 was a second spec branch for the same task; it was diffed in full against #8448 and the salvage assessment is posted on #8448 (its unique elements — names-as-data extraction, per-site diagnostics, build_hash/catalog_commit provenance, the capscan CLI shape, and the uncertified lower-bound critique — are recorded there for the implementation follow-on). Nothing in #8499 is required for #8448: the two specs use mutually exclusive output contracts, and #8448 follows the model the triage of record fixed. #8499 is not merged; its text remains on branch queue/14829-5998-capscan-spec and in this PR.

@dezren39 dezren39 closed this Nov 11, 2026
@dezren39
dezren39 deleted the queue/14829-5998-capscan-spec branch November 14, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id: design: used-capability derivation tool — static call-graph scan producing the registry used-set

1 participant